import request from '@/utils/request.js'

// 创建实习/兼职等帖子
export const createInternshipJob = (internshipJobDTO, coverFile) => {
    const formData = new FormData();
    
    // 添加字段数据
    Object.keys(internshipJobDTO).forEach(key => {
        let value = internshipJobDTO[key];
        
        // 特殊处理数组类型数据，转换为JSON字符串
        // 使用 Array.isArray 或检查对象是否具有数组特征
        if (Array.isArray(value) || (value && typeof value === 'object' && value.constructor === Array)) {
            value = JSON.stringify(value);
        }
        
        formData.append(key, value);
    });
    
    // 添加封面文件（如果存在）
    if (coverFile) {
        formData.append('coverFile', coverFile);
    }
    
    return request.post('/Internships/add', formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    });
}

//获取实习/兼职等帖子列表
export const getInternshipJobList = () => {
    return request.get('/Internships/list')
}

// 根据ID获取实习/兼职详情
export const getInternshipJobById = (id) => {
    return request.get(`/Internships/detail/${id}`)
}

//根据行业获取实习/兼职信息列表
export const getInternshipJobByIndustry = (industry) => {
    return request.get(`/Internships/industry?industry=${industry}`)
}

//根据postId获取实习/兼职信息
export const getInternshipJobByPostId = (postId) => {
    return request.get(`/Internships/detail/post/${postId}`)
}